<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="150px">
      <el-form-item label="Vendor name">
        <el-col :span="8">
          <el-input v-model="form.Vendor" />
        </el-col>
      </el-form-item>
      <el-form-item label="POS UUID">
        <el-col :span="8">
          <el-input v-model="form.PosUid" />
        </el-col>
      </el-form-item>
      <el-form-item label="Expire Datetime">
        <el-col :span="8">
          <el-date-picker v-model="form.ExpireDate" type="datetime" placeholder="Pick a datetime" style="width: 100%;" />
        </el-col>
      </el-form-item>
      <el-form-item label="POS function">
        <el-checkbox-group v-model="form.Feature">
          <el-checkbox label="feature 1" name="feature" />
          <el-checkbox label="feature 2" name="feature" />
          <el-checkbox label="feature 3" name="feature" />
          <el-checkbox label="feature 4" name="feature" />
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="More description">
        <el-col :span="8">
          <el-input v-model="form.Description" type="textarea" />
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">Create</el-button>
        <el-button @click="onCancel">Cancel</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { randomUUID } from '@/utils'
import { postPOSForm } from '@/api/form'

export default {
  data() {
    return {
      form: {
        Vendor: '',
        PosUid: randomUUID(),
        ExpireDate: '',
        Feature: [],
        Description: ''
      }
    }
  },
  methods: {
    onSubmit() {
      postPOSForm(this.form).then(response => {
        const { Data } = response
        if (Data.Status === 0) {
          this.$message({
            message: 'Successfully created!',
            type: 'success'
          })
        } else {
          this.$message({
            message: 'Error: ' + Data.ErrMsg,
            type: 'error'
          })
        }
      }).catch(error => {
        this.$message({
          message: 'Error' + error,
          type: 'error'
        })
      })
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}
</script>

